<template>
  <div class="tpl-wrapper">
    <input type="text" readonly v-model="val">
  </div>
</template>

<script type="text/ecmascript-6">
import tool from 'src/util/tool';
import util from '_util/index';
import logic from '_logic';
const addDays = require('date-fns/add_days');

export default {
  data() {
    return {
      val: '',
    }
  },
  components: {},
  methods: {
    doActive: function({ name, val }) {
      if (name == 'start_date') {
        if (val) {
          let dayAWeekFromNow = addDays(val, 6);
          var myDate = new Date(dayAWeekFromNow);
          let year = myDate.getFullYear();
          let month = myDate.getMonth() + 1;
          if (month < 10) {
            month = '0' + month;
          }
          let day = myDate.getDate();
          if (day < 10) {
            day = '0' + day;
          }
          let end_date = year + "-" + month + "-" + day;
          this.val = end_date;
        }else{
          this.val='';
        }
      }
    }
  },
  watch: {
    val: function(val, old) {
      if (val != old) {
        this.$emit('setVo', this.field.name, val)
      }
    }
  },
  computed: {
  },
  props: ['field'],
  created() {
    util.eventOn(this, 'for_show_type_change', this.doActive)
  },
  mounted() {
  }
};
</script>

<style scoped>

</style>
